/***************************************
 * 说明：本文件主要列举第6章文中所实现的例题
 * *************************************/
#include "main.h"
/*********************************************
 * 例子6.1：定义三个类，重载运算符，输出以上三个类
 * ******************************************/
ostream& operator<<(ostream& out, const Point& point)
{
    out << "[" << point.pointX << "," << point.pointY << "]" << endl;
    return out;
}
float Circle::area() const
{
    return (3.14 * ra * ra);
}
ostream& operator<<(ostream& out, const Circle& circle)
{
    out << "area = " << circle.area() << endl;
    return out;
}
float Cylinder::volume() const
{
    cout << pointX << " " << pointY << " " << high << endl;
    return pointX * pointY * high;
}
ostream& operator<<(ostream& out, const Cylinder& cylinder)
{
    out << "volume = " << cylinder.volume() << endl;
    return out;
}
void exercise1()
{
    Point point(1,2);
    cout << point << endl;

    Circle cir(1,2,3);
    cout << cir << endl;

    Cylinder cylinder(2,3,4);
    cout << cylinder << endl;
}
/******************************
 * 例子6.2：基类与派生类同名函数
 * ***************************/
void Student::display()
{
    cout << "num = " << num << " name = " << name << " sex = " << sex << endl;;
}

void Graduate::display()
{
    Student::display();
    cout << " wage = " << wage << endl;
}
void exercise2()
{
    Student stu(1234, "wang", 'm');
    Graduate gra(8967, "yang", 'w', 896756);

    Student* stu1 = &stu;
    // stu1->display();  // 输出stu的display函数

    stu1 = &gra;
    stu1->display();  // 输出gra的display函数
}
/******************************
 * 例子6.3：基类中有非虚析构函数
 * ***************************/
void exercise3()
{
    Point3* po = new Circle2();
    delete po;
}
int main()
{
    exercise3();
    return 0;
}